package com.app.extended_plugin;

import android.app.Activity;
import android.util.Log;

import com.app.extended_plugin.utlis.ScreenShotListenManager;

import io.flutter.plugin.common.EventChannel;

public class ScreenEventHandler implements EventChannel.StreamHandler, ScreenShotListenManager.OnScreenShotListener {
    private ScreenShotListenManager screenShotListenManager;
    private static final String TAG = "ScreenEventHandler";
    private EventChannel.EventSink events;
    public ScreenEventHandler(Activity mActivity) {
        Log.i(TAG, "ScreenEventHandler: ");
        screenShotListenManager = ScreenShotListenManager.newInstance(mActivity);

    }

    @Override
    public void onListen(Object arguments, EventChannel.EventSink events) {
        Log.i(TAG, "onListen: ");
        this.events = events;
        screenShotListenManager.setListener(this);
        screenShotListenManager.startListen();

    }

    @Override
    public void onCancel(Object arguments) {
        Log.i(TAG, "onCancel: ");
        screenShotListenManager.stopListen();
        screenShotListenManager.setListener(null);
        events = null;
    }

    @Override
    public void onShot(String imagePath) {
        events.success(imagePath);
    }
}
